doctype html
html
	head
		title Miaou - Room Authorizations
		link(rel="icon",type="image/png",href="static/M-32.png")
		link(rel='stylesheet', href='static/themes/'+theme+'/miaou.css')
		script(src="static/jquery-2.1.3.min.js")
		script#locals(type="Application/JSON") !{JSON.stringify(vars)}
		script(src="static/miaou.min.js")
		script(src="static/auths.min.js")
		style.
			.C {
				background: $bg-color;
				padding: 2px;
				display: table-cell;
				vertical-align: top;
			}
			.C1 {
				width: 30%;
			}
			.C2 {
				width: 40%;
			}
			.CC {
				padding: 2px;
			}
			#submit_bar {
				clear:both;
			}
	body
		- authLevels = ['read', 'write', 'admin', 'own']
		- rol = authLevels.indexOf(room.auth)
		- canseeauths = true
		form(method="post")
			input(type="hidden", name="room", value=room.id)
			input(type="hidden", name="secret", value=secret)
			div.MP#auths-page
				h1
					a(href="rooms") Miaou
					| /
					a(href=room.path)= room.name
					button#backToRoom Back to room
				if room.private
					p This room is private, only authorized users can enter.
				else
					p This room is public, everybody can read and write messages but authorizations are needed to change the name and description or manage authorizations.
				p
					case room.auth
						when 'own'
							| As a room owner you can change everybody's rights. You can also &nbsp;
							a(href="room?id="+room.id)
								| edit the room
								if room.private
									| and make it public
								else
									| and make it private
								| .
						when 'admin'
							| As a room admin you can change the rights of everybody, apart owners. You can also &nbsp;
							a(href="room?id="+room.id) edit the room
							| .
						default
							if room.listed || rol>=1
								| Your authorization level doesn't make it possible for you to manage rights in this room.
							else
								- canseeauths = false
								| Room settings prevent unauthorized users to see authorizations.
				if canseeauths
					div.C.C1
						h2 Access Requests
						if requests.length
							table.list
								each r, i in requests
									tr.user-line(data-user={id:r.player})
										th
											span.user= r.name
										td.date= r.requested
										td
											- var name = "answer_request_"+r.player
											div
												input(type="radio", _name=name, id="g"+i, value="grant")
												label(for="g"+i) Grant Access
											div
												input(type="radio", _name=name, id="d"+i, value="deny")
												label(for="d"+i) Deny Access
									tr.user-line
										td
											span= r.name+' '
											| says
										td.rendered(colspan="2")= r.request_message
									tr.user-line.denyMessageTr(style="display:none")
										td(colspan="3")
											input(type="text",style="width:100%",_name="deny_message_"+r.player,placeholder="optional message")
						else
							p none currently
						h2 Recent Users With No Authorization
						if unauthorizedUsers.length
							table.list
								each u in unauthorizedUsers
									tr.user-line(data-user={id:u.id, name:u.name})
										th
											span.user= u.name
										if rol>=2
											td.auth
												- var name = "insert_auth_"+u.id
												select(_name=name)
													option(value="admin") admin
													option(value="write") write
													option(value="none",selected) no access
						else
							p none currently
					div.C.C1
						h2 Existing Authorizations
						table.list
							each ua in auths
								tr.user-line(data-user={id:ua.player})
									th
										span.user= ua.name
									- ual = authLevels.indexOf(ua.auth)
									if rol>=2 && rol>=ual
										td.auth
											- var name = "change_auth_"+ua.player
											select(_name=name)
												if room.auth === 'own'
													option(value="own", selected=ua.auth==="own") own
												option(value="admin", selected=ua.auth==="admin") admin
												option(value="write", selected=ua.auth==="write") write
												option(value="none") no access
									else
										td.auth= ua.auth
					div.C.C2
						h2 Active Bans
						table.list
							each ban in bans
								tr
									th
										span.user=ban.bannedname
									td									
										| banned by
										span.user=' '+ban.bannername+' '
										| until
										span= ' '+new Date(ban.expires*1000)
									td(style="white-space:nowrap")
										- var name = "unban_"+ban.id+"_"+ban.banned
										input(type="checkbox",_name=name,id=name)
										label(for=name) unban
					if rol>=2
						p#submit_bar
							input(type="reset", value="Cancel Changes", disabled)
							input(type="submit", value="Validate Changes", disabled)
